/**
 *	判断业务机会是否超期，超期标准：立项到招标60天、招标到签合同2周
 *	create by Harry 2016-11-30
 */
global class CheckOppTimeout implements Schedulable {
    global void execute(SchedulableContext sc) {
    	Date d1 = Date.today();
    	d1.addDays(-60);
    	Date d2 = Date.today();
    	d2.addDays(-14);
    	Set<String> s = new Set<String>{'立项','方案谈判'};
        List<Opportunity> oppList = [SELECT o.ProjStartDate__c FROM Opportunity o 
        							WHERE o.isTimeout__c = false AND 
        							((o.StageName in :s AND o.ProjStartDate__c<=:d1)
        							OR (o.StageName = '招标' AND o.ProjStartDate__c<=:d2)) ];

        for(Opportunity opp: oppList){
        	opp.IsTimeout__c= true;
        }

        try {
            update oppList;
        }catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
    }    
}